#pragma once
#include "Common.h"

class PageCache
{
private:
    SpanList _spanList[NPAGES];

    static PageCache _sInst;

    PageCache(/* args */)
    {
    }
    PageCache(const PageCache &) = delete;

    unordered_map<PAGE_ID, Span *> _idSpanMap;

public:
    std::mutex _pageMtx;

    ~PageCache()
    {
    }

    static PageCache *GetInstance()
    {
        return &_sInst;
    }

    // 获取一个 k页的 span
    Span *NewSpan(size_t k);
    // 获取对象到 span的映射
    Span *MapObjectToSpan(void *obj);

    // 释放空闲的空间 span, 到pageCache, 并合并相邻的span
    void ReleaseSpanToPagecache(Span* span);
};
